﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using JJYYCore;

public class ObjPoolExampleMoudle : MonoBehaviour
{
    [SerializeField]
    private List<GameObject> objectCollection;
    private ObjectPoolManager poolManager;
    private List<GameObject> res;

    // Start is called before the first frame update
    void Start()
    {
        var factory = new ExampleObjectPoolFactory(objectCollection);
        poolManager = new ObjectPoolManager(factory);
        res = new List<GameObject>();
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.A))
        {
            var obj = (poolManager.Get("ExampleRes") as ExampleCollectionRes).gameObject;
            res.Add(obj);
        }
        else if(Input.GetKeyDown(KeyCode.S)){
            for (int i = 0; i < res.Count; i++)
            {
                var selection = res[i].GetComponent<IPoolRes>();
                poolManager.Collect(selection);
            }
        }
    }
}
